<?php
	$connect = mysql_connect("localhost","root","yxs147789");
	if ($connect) {
	  	mysql_select_db("inspectdb", $connect);
	  	$username = $_POST["username"];
	  	$passwd = $_POST['passwd'];
	  	$querystr = sprintf("SELECT type FROM users WHERE user_name='%s' and pass_wd='%s'", $username, $passwd);
	  	echo $querystr;
	  	$result = mysql_query($querystr);
	  	$row = mysql_fetch_array($result);
	  	if($row) {
	  		$type = $row['type'];
	  		//注册session, 跳转到index.php
	  		session_start();
	  		$_SESSION['userName'] = $username;
	  		$_SESSION['userType'] = $type;
	  		header("location: index.php");
	  	} else { 
	  		//用户名或密码错误，跳转到login.php
	  		header("location: login.php?error=用户名或密码错误");
	  	}
	} else { 
		// 数据库连接错误, 跳转到login.php
		header("location: login.php?error=连接错误");
	}
	mysql_close($connect);
?>